package com.jasonzqshen.ifm.collections.treeCollection.factories;

import java.util.Hashtable;

public class TreeFactoryTable {
    private static TreeFactoryTable staticfactoryTable = new TreeFactoryTable();

    public static TreeFactoryTable getFactoryTable() {
        return staticfactoryTable;
    }

    public Hashtable<String, TreeFactory> factories;

    public TreeFactoryTable() {
        factories = new Hashtable<String, TreeFactory>();
    }

    /**
     * Add Tree Factory
     * 
     * @param treeFactory
     */
    public void addTreeFactory(TreeFactory treeFactory) {
        this.factories.put(treeFactory.getTreeClassName(), treeFactory);
    }

    /**
     * Contain type
     * 
     * @param type
     * @return
     */
    public boolean containType(String type) {
        return this.factories.containsKey(type);
    }

    /**
     * Get all tree types
     * 
     * @return
     */
    public String[] getAllTypes() {
        return (String[]) this.factories.keySet().toArray();
    }

    /**
     * get all factories
     * 
     * @return
     */
    public TreeFactory[] getFactories() {
        return (TreeFactory[]) this.factories.values().toArray();
    }

    /**
     * Get factory. Class name of the tree
     * 
     * @param index
     * @return
     */
    public TreeFactory getFactory(String index) {
        return this.factories.get(index);
    }
}
